<template>

  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col>

      <strong v-if="isRoot"><i class="el-icon-school" /> {{ treeNode.label }}</strong>
      <span v-else>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown class="pointer">
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="editDepartment">编辑子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delDepartment">删除子部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartment } from '@/api/department'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    // 判断是不是头部
    isRoot: {
      type: Boolean,
      required: true
    }
  },

  methods: {
    //   删除
    async delDepartment() {
    //   console.log(1)
      console.log(this.treeNode.id)

      const removeconfirm = await this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).catch(err => err)
      if (removeconfirm === 'cancel') return this.$message.info('用户取消了删除')
      await delDepartment(this.treeNode.id)
      this.$message.success('部门删除成功')
      this.$emit('delDepartment')
    },
    // 点击添加、
    addDepartment() {
      this.$emit('addDepartment', this.treeNode)
    },
    // 点击编辑
    editDepartment() {
      this.$emit('editDepartment', this.treeNode)
    }
  }
}
</script>

<style>

</style>
